﻿using System;
using System.ComponentModel;
using System.Data;
using GatewayInspect.Common;
using System.Data.OracleClient;

namespace GatewayInspect.Model
{
    /// <summary>
    /// 车辆信息
    /// </summary>
    public class TruckInfo_Readonly
    {
        public TruckInfo_Readonly()
        {
        }

        #region Propertys

        /// <summary>
        /// 主键
        /// </summary>
        [Browsable(false)]
        public string ID { get; set; }

        [Category("\t\t\t\t\t基本信息"), DisplayName("上次查验日期"), ReadOnly(true)]
        public DateTime LastInspectTime { get; set; }

        /// <summary>
        /// 车牌号
        /// </summary>
        [Category("\t\t\t\t\t基本信息"), DisplayName("车牌号"), ReadOnly(true)]
        public string TRUCKNO { get; set; }

        [Category("\t\t\t\t\t基本信息"), DisplayName("车辆载质量(吨)"), ReadOnly(true)]
        public double HD_WEIGHT { get; set; }

        /// <summary>
        /// 司机姓名
        /// </summary>
        [Category("\t\t\t\t\t基本信息"), DisplayName("司机姓名"), ReadOnly(true)]
        public string DRIVERNAME { get; set; }

        /// <summary>
        /// 司机身份证号
        /// </summary>
        [Category("\t\t\t\t\t基本信息"), DisplayName("司机身份证号"), ReadOnly(true)]
        public string DRIVERID { get; set; }

        [Category("\t\t\t\t\t基本信息"), DisplayName("灭火器有效期"), ReadOnly(true)]
        public DateTime MHQ_YXQ { get; set; }

        [Category("\t\t\t车辆行驶证"), DisplayName("检验有效期(车头)"), ReadOnly(true)]
        public DateTime XSZ_CT_YXQ { get; set; }

        [Category("\t\t\t车辆行驶证"), DisplayName("检验有效期(车挂)"), ReadOnly(true)]
        public DateTime XSZ_CG_YXQ { get; set; }

        [Category("\t\t中华人民共和国道路运输证"), DisplayName("车辆审验及技术等级记录(车头)"), ReadOnly(true)]
        public DateTime YSZ_CT_SYJL { get; set; }

        [Category("\t\t中华人民共和国道路运输证"), DisplayName("车辆审验及技术等级记录(车挂)"), ReadOnly(true)]
        public DateTime YSZ_CG_SYJL { get; set; }

        [Category("道路运输液体危险货物罐式车辆常压罐体定期检验报告"), DisplayName("有效期"), ReadOnly(true)]
        public DateTime JYBG_YXQ { get; set; }

        [Category("道路运输液体危险货物罐式车辆常压罐体定期检验报告"), DisplayName("检验单位"), ReadOnly(true)]
        public string JYBG_JYDW { get; set; }

        #endregion

        #region static Methods

        public static TruckInfo_Readonly GetInstanceFromDB(string id)
        {
            DataTable dtInfo = DataAccess.ExecuteDataTable("select * from T_TRUCK_CERT_INFO where ID = '" + id + "'");
            if (dtInfo != null && dtInfo.Rows.Count > 0)
            {
                return GetInstanceFromDB(dtInfo.Rows[0]);
            }
            return null;
        }

        public static TruckInfo_Readonly GetInstanceFromDB(DataRow row)
        {
            DateTime dateTemp;
            TruckInfo_Readonly info = new TruckInfo_Readonly();

            info.ID = row["ID"].ToString();
            info.TRUCKNO = row["TRUCKNO"].ToString();
            //info.DRIVERID = row["DRIVERID"].ToString();
            //info.DRIVERNAME = row["DRIVERNAME"].ToString();
            if (DateTime.TryParse(row["XSZ_CT_YXQ"].ToString(), out dateTemp))
                info.XSZ_CT_YXQ = dateTemp;
            if (DateTime.TryParse(row["XSZ_CG_YXQ"].ToString(), out dateTemp))
                info.XSZ_CG_YXQ = dateTemp;
            if (DateTime.TryParse(row["YSZ_CT_SYJL"].ToString(), out dateTemp))
                info.YSZ_CT_SYJL = dateTemp;
            if (DateTime.TryParse(row["YSZ_CG_SYJL"].ToString(), out dateTemp))
                info.YSZ_CG_SYJL = dateTemp;
            if (DateTime.TryParse(row["JYBG_YXQ"].ToString(), out dateTemp))
                info.JYBG_YXQ = dateTemp;
            info.JYBG_JYDW = row["JYBG_JYDW"].ToString();
            if (DateTime.TryParse(row["MHQ_YXQ"].ToString(), out dateTemp))
                info.MHQ_YXQ = dateTemp;
            double dWeight = 0;
            if (double.TryParse(row["HD_WEIGHT"].ToString(), out dWeight))
                info.HD_WEIGHT = dWeight;

            return info;
        }

        #endregion
    }
}
